package com.minelx.serverandclient.common;

import com.minelx.serverandclient.stream.data.StreamCache;

public abstract class Holder {
	protected StreamCache result;

	public Holder() {
		result = StreamCache.empty();
	}

	public abstract StreamCache get();

	public abstract StreamCache fetch();

	public static Holder simple() {
		return new Holder() {
			@Override
			public StreamCache get() {
				return result;
			}

			@Override
			public StreamCache fetch() {
				StreamCache result = this.result;
				this.result = StreamCache.empty();
				return result;
			}
		};
	}

	public static Holder singleton() {
		return new Holder() {
			@Override
			public StreamCache get() {
				return result;
			}

			@Override
			public StreamCache fetch() {
				return result;
			}
		};
	}
}
